﻿using System.Collections.Concurrent;
using System.Net.Mail;
using NetFluid;

namespace Sito
{
    internal class Mailer : FluidPage
    {
        private static SmtpClient _client;

        public static string SMTPServer = "localhost";

        public override void OnServerStart()
        {
            _client = new SmtpClient(SMTPServer);
        }

        public static void Send(string toaddress, string subject, string body, string to, string fromaddress,string from)
        {

            var mail = new MailMessage
                           {
                               From = new MailAddress(fromaddress, from),
                               Subject = subject,
                               Body = "<html><head></head><body>" + body + "</body></html>",
                               IsBodyHtml = true
                           };
            mail.To.Add(new MailAddress(toaddress, to));

            lock (_client)
            {
                _client.Send(mail);
            }
        }
    }
}